<template>
    <div class="profile-avatar">
        <m-img-uploader @selected="selectedAvatar"></m-img-uploader>
        <div class="modify-btn">
            <m-button value="修改" @click.native="uploadAvatar"></m-button>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                base64URL: null
            }
        },
        methods: {
            selectedAvatar(e) {
                this.base64URL = e;
            },
            uploadAvatar() {
                const self = this;
                let data = {
                    type: 'avatar',
                    value: this.base64URL
                }
                if (this.base64URL && typeof this.base64URL === 'string') {
                    this.$http.userEdit(data).then(res => {
                        if (res.success === true) {
                            self.$store.dispatch("updateUserInfo", {name: 'avatar', value: res.data});
                            self.$mToast('修改成功');
                            self.back();
                        }
                    }, error => {

                    });
                } else {

                }
            }
        }
    }
</script>
<style lang="less" scoped>
    .profile-avatar {
        .modify-btn {
            margin: 30px auto 0px auto;
        }
    }
</style>